﻿@{
    ViewBag.Title = "";
    var id = Model != null ? Model.ID : 0;
}
@using ZBJF.Warranty.BLL
@using ZBJF.Warranty.WebProvider
@using ZBJF.Warranty.Common.Enums.InsuranceWarranty
@using EnumHelper = ZBJF.Warranty.Common.Common.EnumHelper
@model ZBJF.Warranty.Model.AuditProjectConfiguration
<ul class="nav nav-tabs">
    <li><a href="/AuditProjectConfiguration/AuditProjectConfigurationIndex">审核项目列表</a></li>
    <li class="active"><a href="/AuditProjectConfiguration/AuditProjectConfigurationEdit/@id">@(id > 0 ? "编辑审核项目" : "添加审核项目")</a></li>
</ul>
@using (Html.BeginForm("SaveAuditProjectConfiguration", "AuditProjectConfiguration", FormMethod.Post, new { id = "mvcForm", name = "mvcForm", @class = "form-horizontal", enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()
    @Html.HiddenFor(c => c.ID)
    <div class="control-group">
        <label class="control-label">审核项目类型：</label>
        <div class="controls">
            @Html.DropDownListFor(m => m.AuditProjectWithType, ConvertToSelector.Instance.EnumTypeConvertToSelectList(typeof(AuditProjectTypeEnum), Model.AuditProjectWithType), new { validate = "{required:true,messages:{required:'请选择审核项目类型'}}" })
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">审核项目名称：</label>
        <div class="controls">
            @Html.TextBoxFor(m => m.ProjectName, new { validate = "{required:true,messages:{required:'请输入审核项目名称'}}", maxLength = 30 })
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">字段类型：</label>
        <div class="controls">
            @Html.DropDownListFor(m => m.FieldType, ConvertToSelector.Instance.EnumTypeConvertToSelectList(typeof(FieldTypeEnum), Model.FieldType), new { validate = "{required:true,messages:{required:'请选择字段类型'}}" })
        </div>
    </div>
    <div id="textField" style="display:none">
        <div class="control-group" style="display:block">
            <label class="control-label">最大长度：</label>
            <div class="controls">
                @Html.TextBoxFor(m => m.MaxLength, new { maxLength = 4, onkeyup = "onlyInputInt(this)" })
            </div>
        </div>
    </div>
    <div id="fieldOption" style="display:none">
        <div class="control-group" style="display:block">
            <label class="control-label">选项：</label>

            @for (int j = 0; j < Model.AuditProjectFieldOption.Count; j++)
            {
                var AuditProjectFieldOption = Model.AuditProjectFieldOption.ToList();
                <div class="controls">
                    <span>
                        @Html.TextBoxFor(m => AuditProjectFieldOption[j].OptionName, new { validate = "{required:true,messages:{required:'请输入选项名称'}}", MaxLength = "30" })
                    </span>
                    @if (j > 0)
                    {
                        <a class='Edit-R red optionDelete' href="javascript:void(0)" title="删除"><i class='icon-remove'></i></a>
                    }
                    <a class='Edit-R optionAdd' href="javascript:void(0)" title="新增"><i class="icon-plus"></i></a>
                </div>
            }
        </div>
    </div>

    <div class="control-group">
        <label class="control-label"></label>
        <div class="controls">
            <label>
                @Html.CheckBoxFor(m => m.IsAvailable)
                是否可用
            </label>
        </div>
    </div>
    <div class="form-actions">
        <input id="btnSubmit" class="btn btn-primary Edit-R" type="button" value="保存" onclick="loading(this)">
        <input id="btnCancel" class="btn" type="button" value="重置" onclick="reset()">
    </div>
}
@section scripts{
    <script>
        $(function () {
            var type = $("#FieldType").val();
            if (type == 5 || type == 10 || type == 30) {
                $("#textField").show();
            }
            else if (type == 15 || type == 20 || type == 25) {
                $("#fieldOption").show();
            }

            //字段类型选择事件
            $("#FieldType").on("change", function () {
                var _value = $(this).val();
                if (_value == 5 || _value == 10 || _value == 30) {
                    $("#textField").show();
                    $("#fieldOption").hide();
                } else {
                    $("#fieldOption").show();
                    $("#textField").hide();
                }
            })

            //删除选项
            $(document).on("click", ".optionDelete", function () {
                $(this).parent(".controls").remove();
            })

            //新增选项
            $(document).on("click", ".optionAdd", function () {
                var _count = $(".optionAdd").length
                if (_count > 7) {
                    layer.alert("最多添加8个选项");
                    return;
                }
                var _html = '<div class="controls">';
                _html += '<span>';
                _html += ' <input maxlength="30" id="AuditProjectFieldOption_' + _count + '__OptionName" name="AuditProjectFieldOption[' + _count + '].OptionName" type="text" value="" validate = "{required:true,messages:{required:\'请输入选项名称\'}}">';
                _html += ' </span>';
                _html += '  <a class="Edit-R red optionDelete" href="javascript:void(0)" title="删除"><i class="icon-remove"></i></a>';
                _html += '  <a class="Edit-R optionAdd" href="javascript:void(0)" title="新增"><i class="icon-plus"></i></a>';
                _html += ' </div>';
                $(this).parent(".controls").parent(".control-group").append(_html);
            })
        })


        function reset() {
            document.getElementById("mvcForm").reset();
        }
        function loading(_this) {
            if ($("#mvcForm").valid()) {
                _this.disabled = 'disabled';
                document.getElementById("mvcForm").submit();
            }
        }
    </script>
}